const app = getApp();

import { getStorage } from "../../../utils/localStorage"
import { eventHandle } from "../../../api/event"
import { baseUrl } from "../../../api/request"
Page({
    data: {
        navData: {
            title: '处理事件',
            level: 2,
        },
        navMargin: app.globalData.navHeight + app.globalData.navTop,
        form: {
            id: "",
            handleResult: "",
            handleImage: "",
            handleName: "",
        },
        detailObj: {},
        user: null,
        baseUrl: null,
    },
    onLoad(options) {
        this.setValue();
        let item = JSON.parse(decodeURIComponent(options.item));
        this.setData({
            detailObj: item,
        });
    },
    //初始化页面值
    setValue() {
        this.setData({
            baseUrl: baseUrl,
            user: getStorage('user'),
        });
    },
    //输入框事件
    textInput(e) {
        const value = e.detail.value;
        this.setData({
            "form.handleResult": value,
        });
    },
    //上传图片事件
    upload(e) {
        let value = e.detail.join(",");
        this.setData({
            "form.handleImage": baseUrl + value,
        });
    },
    //提交按钮事件
    async submit(e) {
        let _this = this.data;
        this.setData({
            "form.id": this.data.detailObj.id,
            "form.handleName": this.data.username,
        });
        if (!_this.form.handleName && !_this.form.handleImage) {
            wx.showToast({
                icon: "none",
                title: '处理结果和处理图片不能为空!!!',
            });
        } else {
            let res = await eventHandle(_this.form);
            let { code } = res.data;
            if (code === 200) {
                wx.showToast({
                    icon: "none",
                    title: '处理完成',
                    duration: 1000,
                })
                setTimeout(() => {
                    wx.redirectTo({
                      url: '/pagesXiaoXi/pages/event/index',
                    })
                }, 1100)
            };
        }

    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})